cmake_minimum_required(VERSION 3.5)

set(CXX_FLAGS
  -g
  # -DVALGRIND
  -DCHECK_PTHREAD_RETURN_VALUE
  -D_FILE_OFFSET_BITS=64
  -Wall
  # -MMD
  -std=c++14
  # -rdynamic
)
if(CMAKE_HOST_UNIX)
  set(CXX_FLAGS ${CXX_FLAGS}
    -Wextra
    -Werror
    # -Wconversion
    -Wno-unused-parameter
    # -Wold-style-cast
    # -Woverloaded-virtual
    -Wpointer-arith
    # -Wshadow
    -Wwrite-strings
    -march=native
  )
endif()
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}")

set(TARGET_TEST_LINK_LIBS xlcomm_base xlcomm_net)

if(CMAKE_HOST_UNIX)
  set(TARGET_TEST_LINK_LIBS ${TARGET_TEST_LINK_LIBS} pthread protobuf z)
endif()

link_directories(/usr/local/lib)

set(MY_TEST_BIN
  test_proto
  query_server
  query_client
)
FOREACH(test ${MY_TEST_BIN})
  add_executable(${test} ${test}.cc query.pb.cc codec.cc)
  target_link_libraries(${test} ${TARGET_TEST_LINK_LIBS})
ENDFOREACH(test)